//
//  MacroDefinition.h
//  laicunba
//
//  Created by binbinming on 4/24/11.
//  Copyright (c) 2017 xings. All rights reserved.
//
//

#ifndef MacroDefinition_h
#define MacroDefinition_h

//------------------加密的key----------------
#define kKey @"Y0aQtIa9HZKwrRVZWeZOi61x"

// RSA 加密的公钥
#define PUBLICKEY @"-----BEGIN PUBLIC KEY-----MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCe5X0vkxrzbcRO776Ljt3V1NqeSNpmiPaPzyYvitsQMM0GKN8Ehts2hSgiikwaTWpCrtNRRh0jG80LNN1wGEa3RR0Nus1KhpgxmGWialcKWWdtEzcKSMwX616NYvnW2LpRYvPOuIfDnOIqc1c2+xZKbCGNcAr/L0F3lH3iyBOtYQIDAQAB-----END PUBLIC KEY-----"

// RSA 加密的私钥
#define PRIVATEKEY @"-----BEGIN PRIVATE KEY-----MIICdwIBADANBgkqhkiG9w0BAQEFAASCAmEwggJdAgEAAoGBAJ7lfS+TGvNtxE7vvouO3dXU2p5I2maI9o/PJi+K2xAwzQYo3wSG2zaFKCKKTBpNakKu01FGHSMbzQs03XAYRrdFHQ26zUqGmDGYZaJqVwpZZ20TNwpIzBfrXo1i+dbYulFi8864h8Oc4ipzVzb7FkpsIY1wCv8vQXeUfeLIE61hAgMBAAECgYEAk5w5iYKtHMsx/Oq3JsqXxlewqC6hxXMjKkGUBcKG8ymCrWA2nevxpVpaCIxVWnHkbwIeCXiLBNyExQ5dUA8dURkJn41J3bQEq/yUmTZHrlCerm1bxChte1peHjBzVsL5S3swJWTPabt8v3D6rOXbJRTHqjkvSBUnn727Qdf0cWECQQDRCl6rI52sBNqTPy5CW8fOliPXcrZoBqaZDfZF1QSXoiFvJHNYiXYpTb2D0r0VNP4FsBxmdCZeMKrQlQrdAqc9AkEAwpdnRaWtKltdZ/7YSXLI3opYg4SKwkvFmrMMgKqUwLQEcEIp8nQYVyLZNjepkgSslRSLLf85Eoct+c/EeEog9QJANXCDNxkJy9oJzq7OMqSn9cYoL4Hh48IfgO0y0jNc0y7dgT4+RpoNnQ2Er1iGgg9kCSw2dnKnBFlIsb4IYuu0uQJAdSJiXgBe/rJExccYNw5Lb/pjUbfFNzQZXQgOrJ0CMgWq7lBFo9bSmBE4I3TaNDVwFcVqCmQp3MdWm5u/rpEgyQJBAJfDGc9GlzXH+QsIjmtygbHKyA3Vi4LVDGiy42SzKqhudQ5ScYPkjb5LPjgFrcY6sHhE6QBb0Of+F7LkfGOl4Nk=-----END PRIVATE KEY-----"

/// APPID
#define APPID @"1485357941"
///微信appid
#define WeiXinAPPID @"wx0ca4d60f1ca03410"
/// 友盟appkey
#define UMAPP_KEY   @"5db7d1f40cafb25d240010d4"

//-------------------获取设备大小------------------------

// xr
#define IsiPhoneXr ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) : NO)
///以后不要用了
#define kStatusBarHeight [[UIApplication sharedApplication] statusBarFrame].size.height
#define kNavBarHeight 44.0
///获取状态栏高度，放到传过来的 statusBarH 变量中
#define getStatusBarHeight(statusBarH) \
if (@available(iOS 13.0, *)) { \
    statusBarH = [UIApplication sharedApplication].keyWindow.windowScene.statusBarManager.statusBarFrame.size.height; \
} else { \
    statusBarH = [UIApplication sharedApplication].statusBarFrame.size.height; \
}
// status 和 NavBar 的高度
#define StatusBarAndNavBar_Height ([[UIApplication sharedApplication] statusBarFrame].size.height + 44)
// tabar 高度
#define Tabbar_Height ([[UIApplication sharedApplication] statusBarFrame].size.height > 20 ? 83 : 49)
// tabbar 下方的一段高度（iPhone X）
#define Tabbar_Bottom_height ([[UIApplication sharedApplication] statusBarFrame].size.height > 20 ? 34 : 0)

//获取屏幕 宽度、高度
#define SCREEN_WIDTH ([UIScreen mainScreen].bounds.size.width)
#define SCREEN_HEIGHT ([UIScreen mainScreen].bounds.size.height)

#define kScale SCREEN_WIDTH / 375.0

//-------------------获取设备大小-------------------------

//-------------------打印日志-------------------------

//重写NSLog,Debug模式下打印日志和当前行数
#if DEBUG
#define NSLog(FORMAT, ...) fprintf(stderr,"\nfunction:%s line:%d content:%s\n", __FUNCTION__, __LINE__, [[NSString stringWithFormat:FORMAT, ##__VA_ARGS__] UTF8String]);
#else
#define NSLog(FORMAT, ...) nil
#endif



#define ITTDEBUG
#define ITTLOGLEVEL_INFO     10
#define ITTLOGLEVEL_WARNING  3
#define ITTLOGLEVEL_ERROR    1

#ifndef ITTMAXLOGLEVEL

#ifdef DEBUG
#define ITTMAXLOGLEVEL ITTLOGLEVEL_INFO
#else
#define ITTMAXLOGLEVEL ITTLOGLEVEL_ERROR
#endif

#endif

// The general purpose logger. This ignores logging levels.
#ifdef ITTDEBUG
#define ITTDPRINT(xx, ...)  NSLog(@"%s(%d): " xx, __PRETTY_FUNCTION__, __LINE__, ##__VA_ARGS__)
#else
#define ITTDPRINT(xx, ...)  ((void)0)
#endif

// Prints the current method's name.
#define ITTDPRINTMETHODNAME() ITTDPRINT(@"%s", __PRETTY_FUNCTION__)

// Log-level based logging macros.
#if ITTLOGLEVEL_ERROR <= ITTMAXLOGLEVEL
#define ITTDERROR(xx, ...)  ITTDPRINT(xx, ##__VA_ARGS__)
#else
#define ITTDERROR(xx, ...)  ((void)0)
#endif

#if ITTLOGLEVEL_WARNING <= ITTMAXLOGLEVEL
#define ITTDWARNING(xx, ...)  ITTDPRINT(xx, ##__VA_ARGS__)
#else
#define ITTDWARNING(xx, ...)  ((void)0)
#endif

#if ITTLOGLEVEL_INFO <= ITTMAXLOGLEVEL
#define ITTDINFO(xx, ...)  ITTDPRINT(xx, ##__VA_ARGS__)
#else
#define ITTDINFO(xx, ...)  ((void)0)
#endif

#ifdef ITTDEBUG
#define ITTDCONDITIONLOG(condition, xx, ...) { if ((condition)) { \
ITTDPRINT(xx, ##__VA_ARGS__); \
} \
} ((void)0)
#else
#define ITTDCONDITIONLOG(condition, xx, ...) ((void)0)
#endif

#define ITTAssert(condition, ...)                                       \
do {                                                                      \
    if (!(condition)) {                                                     \
        [[NSAssertionHandler currentHandler]                                  \
         handleFailureInFunction:[NSString stringWithUTF8String:__PRETTY_FUNCTION__] \
         file:[NSString stringWithUTF8String:__FILE__]  \
         lineNumber:__LINE__                                  \
         description:__VA_ARGS__];                             \
    }                                                                       \
} while(0)

//---------------------打印日志--------------------------


//----------------------系统----------------------------

//获取系统版本
#define IOS_VERSION [[[UIDevice currentDevice] systemVersion] floatValue]
#define CurrentSystemVersion [[UIDevice currentDevice] systemVersion]

// 获取当前版本
#define kCurrentVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]

//获取当前语言
#define CurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])

//判断是否 Retina屏、设备是否%fhone 5、是否是iPad
#define isRetina ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 960), [[UIScreen mainScreen] currentMode].size) : NO)
#define iPhone5 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(640, 1136), [[UIScreen mainScreen] currentMode].size) : NO)



//判断是真机还是模拟器
#if TARGET_OS_IPHONE
//iPhone Device
#endif

#if TARGET_IPHONE_SIMULATOR
//iPhone Simulator
#endif

//检查系统版本
#define SYSTEM_VERSION_EQUAL_TO(v)                  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)
#define SYSTEM_VERSION_GREATER_THAN(v)              ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)
#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v)  ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN(v)                 ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)
#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v)     ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)


//----------------------系统----------------------------


//----------------------内存----------------------------

//使用ARC和不使用ARC
#if __has_feature(objc_arc)
//compiling with ARC
#else
// compiling without ARC
#endif

#pragma mark - common functions
#define RELEASE_SAFELY(__POINTER) { [__POINTER release]; __POINTER = nil; }

//释放一个对象
#define SAFE_DELETE(P) if(P) { [P release], P = nil; }

#define SAFE_RELEASE(x) [x release];x=nil



//----------------------内存----------------------------


//----------------------图片----------------------------

//读取本地图片
#define LOADIMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:file ofType:ext]]

#define XS_IMAGE(file,ext) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[NSString stringWithFormat:@"%@@%.0fx",file,[UIScreen mainScreen].scale] ofType:ext]]

//定义UIImage对象
#define IMAGE(A) [UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:A ofType:nil]]

//定义UIImage对象
#define ImageNamed(_pointer) [UIImage imageNamed:[UIUtil imageName:_pointer]]

//image文件路径
#define kMainBundleImageURL(file,ext) [[NSBundle mainBundle] URLForResource:[file stringByAppendingString:[NSString stringWithFormat:@"@%.0fx",[UIScreen mainScreen].scale]] withExtension:ext]

//建议使用前两种宏定义,性能高于后者
//----------------------图片----------------------------



//----------------------颜色类---------------------------
// rgb颜色转换（16进制->10进制）
#define UIColorFromRGB(rgbValue) [UIColor colorWithRed:((float)((rgbValue & 0xFF0000) >> 16))/255.0 green:((float)((rgbValue & 0xFF00) >> 8))/255.0 blue:((float)(rgbValue & 0xFF))/255.0 alpha:1.0]

//带有RGBA的颜色设置
#define COLOR(R, G, B, A) [UIColor colorWithRed:R/255.0 green:G/255.0 blue:B/255.0 alpha:A]

// 获取RGB颜色
#define RGBA(r,g,b,a) [UIColor colorWithRed:r/255.0f green:g/255.0f blue:b/255.0f alpha:a]
#define RGB(r,g,b) RGBA(r,g,b,1.0f)

//背景色
#define BACKGROUND_COLOR [UIColor colorWithRed:24.0/255.0 green:29.0/255.0 blue:33.0/255.0 alpha:1.0]

//清除背景色
#define CLEARCOLOR [UIColor clearColor]

#pragma mark - color functions
#define RGBCOLOR(r,g,b) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:1]
#define RGBACOLOR(r,g,b,a) [UIColor colorWithRed:(r)/255.0f green:(g)/255.0f blue:(b)/255.0f alpha:(a)]

//----------------------颜色类--------------------------

// 分割线颜色
#define kSeparatorColor UIColorHex(F1F5F6)
// 主色调
#define kMainColor UIColorHex(6822B7)


//----------------------其他----------------------------

//设置View的tag属性
#define VIEWWITHTAG(_OBJECT, _TAG)    [_OBJECT viewWithTag : _TAG]
//程序的本地化,引用国际化的文件
#define MyLocal(x, ...) NSLocalizedString(x, nil)

//NSUserDefaults 实例化
#define USER_DEFAULT [NSUserDefaults standardUserDefaults]


//由角度获取弧度 有弧度获取角度
#define degreesToRadian(x) (M_PI * (x) / 180.0)
#define radianToDegrees(radian) (radian*180.0)/(M_PI)

//获取plist资源路径
#define GetPlistResource(filename) [[NSBundle mainBundle] pathForResource:filename ofType:@"plist"]

//获取HTML地址
#define kGetHTMLDic [[NSDictionary alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"HTMLURL" ofType:@"plist"]]

//创建静态实例化
#define STATIC_SELF(CLASSNAME) \
+ (CLASSNAME*)SELF \
{ \
   return [[self alloc] init]; \
} \

// 对类归档
#define LLArchiveImplementation \
- (instancetype)initWithCoder:(NSCoder *)aDecoder\
{\
self = [super init];\
if (self) {\
[self decode:aDecoder];\
}\
return self;\
}\
- (void)encodeWithCoder:(NSCoder *)aCoder\
{\
[self encode:aCoder];\
}



//单例化一个类
#define SINGLETON_INTERFACE(CLASSNAME)  \
+ (CLASSNAME*)shared;

#define SINGLETON_IMPLEMENTATION(CLASSNAME) \
\
static CLASSNAME* g_shared##CLASSNAME = nil; \
\
+ (CLASSNAME*)shared \
{ \
if (g_shared##CLASSNAME != nil) { \
return g_shared##CLASSNAME; \
} \
\
@synchronized(self) { \
if (g_shared##CLASSNAME == nil) { \
g_shared##CLASSNAME = [[self alloc] init]; \
} \
} \
\
return g_shared##CLASSNAME; \
} \
\
+ (id)allocWithZone:(NSZone*)zone \
{ \
@synchronized(self) { \
if (g_shared##CLASSNAME == nil) { \
g_shared##CLASSNAME = [super allocWithZone:zone]; \
return g_shared##CLASSNAME; \
} \
} \
NSAssert(NO, @ "[" #CLASSNAME \
" alloc] explicitly called on singleton class."); \
return nil; \
} \
\
- (id)copyWithZone:(NSZone*)zone \
{ \
return self; \
}

#endif
